﻿using System.Collections.Generic;
using System;
using System.ComponentModel;

namespace HCI.Questionaire.Entities
{
    public abstract class Question 
    {
        public event Action<Answer> AnswerValueChange;

        public string QuestionText { get; set; }
        public List<Answer> AnswerCollection { get; set; }
        public void AddAnswer(Answer ans)
        {
            ((INotifyPropertyChanged)ans).PropertyChanged += new PropertyChangedEventHandler(Question_PropertyChanged);
            this.AnswerCollection.Add(ans);
        }

        void Question_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "AnswerResult" || e.PropertyName == "IsAnswered")
            {
                this.OnAnswerValueChange((Answer)sender);
            }
        }


        protected void OnAnswerValueChange(Answer ans)
        {
            if (this.AnswerValueChange != null)
            {
                this.AnswerValueChange(ans);
            }

        }

        public abstract void ValidateAnswer();
    }
}